Skip to content

refactor!: replace Trap with extensible ErrorSink and dispatch overrides - #249

Merged
tisonkun merged 5 commits into
mainfrom
refactor/core-error-sink
Nov 25, 2026
Merged

tisonkun merged 5 commits into
mainfrom
refactor/core-error-sink

Conversation

@tisonkun

@tisonkun tisonkun commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Internal runtime failures were previously split across Trap (configured separately on AsyncBuilder and FileBuilder) and hardcoded stderr writes with panic! fallbacks inside Logger, allowing broken stderr pipes to crash host processes while hiding log rotation failures inside RollingFileWriter.

This change unifies pipeline error reporting around ErrorSink under pub mod error per DESIGN.md:

  • Replace Trap and BestEffortTrap with pub trait ErrorSink: fmt::Debug + Send + Sync + 'static under logforth_core::error (logforth::error), accompanied by zero-sized #[non_exhaustive] StderrErrorSink and BlackHoleErrorSink structs, forwarding implementations for Arc<T> and &'static T, and an explicit best-effort terminal contract.
  • Refine Error causal chain formatting ({err} single-layer message, {err:#} inline chain used by StderrErrorSink, {err:?} multi-line Caused by: report).
  • Add LoggerBuilder::error_sink as the logger-wide failure fallback and DispatchBuilder::error_sink as an optional per-dispatch override, removing Logger's stderr panic! paths.
  • Wire .error_sink(...) onto AsyncBuilder and starter_log builders.
  • Remove FileBuilder::trap so File surfaces errors uniformly through its owning Dispatch or Async worker, and ensure RollingFileWriter writes the current record to the active file before returning any rollover or cleanup error.

Consolidate `Error` and runtime error handling under a single-word
`error` module in `logforth-core` and `logforth`, replacing `Trap` and
`BestEffortTrap` with `ErrorSink`, `StderrErrorSink`, and
`BlackHoleErrorSink`.

`ErrorSink` defines the best-effort, non-panicking terminal error
handling contract for pipeline execution roots and implements forwarding
for `Arc<T>` and `&'static T` so stateful error sinks can be shared
across dispatches and loggers.

Refine `Error` formatting to walk standard `.source()` causal chains
without special-casing nested `Error` downcasts: `{err}` renders only
the current message, `{err:#}` renders the inline `: `-separated chain
used by `StderrErrorSink`, `{err:?}` renders a multi-line `Caused by:`
report, and `{err:#?}` renders the raw debug structure.

Signed-off-by: tison <wander4096@gmail.com>
Add `LoggerBuilder::error_sink` (defaulting to `StderrErrorSink`) as the
logger-wide fallback for append and flush failures, and add
`DispatchBuilder::error_sink` as an optional per-dispatch override.

Remove the hardcoded `stderr` writes and `.unwrap_or_else(|e| panic!(...))`
fallbacks from `Logger::log` and `Logger::flush` so broken standard
error pipes cannot crash the host application and sibling appenders and
dispatches remain isolated on failure.

Signed-off-by: tison <wander4096@gmail.com>
Remove `FileBuilder::trap` so `File` operates as a pure leaf `Append`
that surfaces runtime I/O and rotation errors to its owning `Dispatch`
or `Async` worker.

Update `RollingFileWriter::write_all` to defer any date/size rollover or
old-log cleanup error until after writing the current record to the
active file, preventing data loss when log rotation fails.

Signed-off-by: tison <wander4096@gmail.com>
Replace `AsyncBuilder::trap` with `AsyncBuilder::error_sink` (defaulting
to `StderrErrorSink`) and wrap background worker append and flush
failures with consistent causal context before forwarding to the sink.

Expose `.error_sink(...)` on `LogStarterBuilder`,
`LogStarterTestingBuilder`, and `LogStarterStdStreamBuilder` so
applications using `starter_log` can customize pipeline error handling.

Signed-off-by: tison <wander4096@gmail.com>
Document the best-effort, non-panicking `ErrorSink` contract in
`DESIGN.md` and record the `ErrorSink` migration in `CHANGELOG.md`.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun force-pushed the refactor/core-error-sink branch from 4b323ff to 06a43ee Compare November 25, 2026 07:34
@tisonkun
tisonkun merged commit 23ddfb8 into main Nov 25, 2026
10 checks passed
@tisonkun
tisonkun deleted the refactor/core-error-sink branch November 25, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant